using System.Collections.Generic;
using UnityEngine;

public class SceneInitialization : MonoBehaviour
{
	public string[] clipNames;

	private Dictionary<string, List<GameObject>> m_TempPool = new Dictionary<string, List<GameObject>>();

	private static SceneInitialization m_Instance;

	public static SceneInitialization Instance => m_Instance;

	private void Awake()
	{
		if ((bool)m_Instance)
		{
			UnityEngine.Object.Destroy(base.gameObject);
		}
		else
		{
			m_Instance = this;
		}
	}

	private void Start()
	{
		for (int i = 0; i < clipNames.Length; i++)
		{
			AudioManager.Load(clipNames[i]);
		}
	}

	public void LoadClip(string[] clipNames)
	{
		for (int i = 0; i < clipNames.Length; i++)
		{
			AudioManager.Load(clipNames[i]);
		}
	}

	public void OnDestroy()
	{
		for (int i = 0; i < clipNames.Length; i++)
		{
			AudioManager.Unload(clipNames[i]);
		}
		m_Instance = null;
	}

	public void InitObject(string name, int count, GameObject prefab)
	{
		if (m_TempPool.ContainsKey(name))
		{
			List<GameObject> list = m_TempPool[name];
			if (count > list.Count)
			{
				for (int i = list.Count; i < count; i++)
				{
					GameObject gameObject = SupportTools.AddChild(base.gameObject, prefab);
					gameObject.SetActive(value: false);
					list.Add(gameObject);
				}
				m_TempPool[name] = list;
			}
		}
		else
		{
			List<GameObject> list = new List<GameObject>();
			for (int j = 0; j < count; j++)
			{
				GameObject gameObject2 = SupportTools.AddChild(base.gameObject, prefab);
				gameObject2.SetActive(value: false);
				list.Add(gameObject2);
			}
			m_TempPool.Add(name, list);
		}
	}

	public GameObject GetObject(string name)
	{
		if (m_TempPool.ContainsKey(name))
		{
			List<GameObject> list = m_TempPool[name];
			for (int i = 0; i < list.Count; i++)
			{
				if (!list[i].activeInHierarchy)
				{
					list[i].SetActive(value: true);
					return list[i];
				}
			}
		}
		return null;
	}
}
